package com.iexbuy.ihg.adapter;

import android.content.Context;
import android.graphics.Paint;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.iexbuy.ihg.App;
import com.iexbuy.ihg.R;
import com.iexbuy.ihg.entity.Shop;
import com.iexbuy.ihg.entity.ShopItemListObject;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

;

public class ShopItemListAdapter extends BaseAdapter {

	private List<ShopItemListObject> datas = new ArrayList<ShopItemListObject>();
	private Context context;

	public ShopItemListAdapter(Context context, List<ShopItemListObject> datas) {
		super();
		this.context = context;
		if (datas != null) this.datas = datas;
	}

	@Override
	public int getCount() {
		return datas.size();
	}

	@Override
	public Object getItem(int location) {
		return datas.get(location);
	}

	@Override
	public long getItemId(int arg0) {
		return arg0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if (convertView == null) {
			convertView = LayoutInflater.from(context).inflate(R.layout.fragment_shop_detail_list_item, null);
		}
		ShopItemListObject vo = (ShopItemListObject)datas.get(position);


		((TextView) convertView.findViewById(R.id.listTitle)).setText(vo.getItemName());
		((TextView) convertView.findViewById(R.id.listSubTitle)).setText(vo.getSummary());


		if ("1".equalsIgnoreCase(vo.getPayType())) {//金币支付
			((TextView) convertView.findViewById(R.id.currentPrice)).setText("金币" + new BigDecimal(vo.getNewPrice()).setScale(0, BigDecimal.ROUND_DOWN).toString());
			((TextView) convertView.findViewById(R.id.oldPrice)).setVisibility(View.GONE);
		} else {
			((TextView) convertView.findViewById(R.id.currentPrice)).setText("￥" + vo.getNewPrice());
			((TextView) convertView.findViewById(R.id.oldPrice)).setText("￥" + vo.getOldPrice());
		}

		((TextView) convertView.findViewById(R.id.oldPrice)).getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);//删除线
		((TextView) convertView.findViewById(R.id.saledNumber)).setText("已售 " + vo.getSaledNumber());
		App.bitmapUtils.display((ImageView) convertView.findViewById(R.id.listIcon), vo.getThumbnailUrl());

		return convertView;
	}
	
	private Double getMagnitude(String magnitudeStr) {
		Double magnitude = Double.valueOf("0");
		try {
			magnitude = Double.valueOf(magnitudeStr);
		} catch (Exception e) {
		}
		return magnitude;
	}
	
}
